let app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    phoneNum: '',
    promptDialog: false,
    dialogIcon: '',
    header_bg: 'https://mmecoa.qpic.cn/sz_mmecoa_png/iauAIibMdU78szWZBHxmrTXyWk34YvKJPZibRmEY66l37vibvsYH5pbdlHeyjia0K9PV9h0POmuqtKvpCF2T1A1ribDg/640?wx_fmt=png&amp;from=appmsg',
  },

  // 发送作者
  setAuthorCon() {
    let userInfo = wx.getStorageSync('userInfo')

    let data = { name: this.data.name, phoneNum: this.data.phoneNum, user_id: userInfo.user.id };
    let that = this;
    wx.request({
      url: `${app.globalData.API_URL}/setAuthorCon`,
      method: 'POST',
      data: data,
      header: {
        'content-type': 'application/json',
      },
      success(res) {
        if (res.statusCode) {
          that.setData({ promptDialog: true });
        }
      },
    });
  },

  // 确定提交
  confirm() {
    if(this.data.name == '' || this.data.phoneNum == '') {
      this.setData({ dialogIcon: 'version' })
    } else {
      this.setAuthorCon();
      this.setData({ dialogIcon: 'wancheng-kok', phoneNum: '', name: '' })
    }
  },

  // 马赛克页面点击
  onPromptDialog() {
    this.setData({ promptDialog: false });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: 'قىيات ئاۋازلىق ئەسەر',
      path: '/pages/author/author',
      imageUrl: 'https://mmecoa.qpic.cn/sz_mmecoa_png/iauAIibMdU78thJHXKBcIfYLNA6zH3pbFllMLlSibhVriaGwtS0bM1tLLyz6OSlQ74icF6c4Yic4icLokYGvb2jXnY8bA/640?wx_fmt=png&amp;from=appmsg'
    };
  }
})